//
//  YTHDLikeCell.m
//  yitaicaijing
//
//  Created by DIANGHONG on 2018/7/17.
//  Copyright © 2018年 DIANGHONG. All rights reserved.
//

#import "YTHDLikeCell.h"
@interface YTHDLikeCell ()
@property (weak, nonatomic) IBOutlet UIButton *likeButton;

@end
@implementation YTHDLikeCell



- (void)setModel:(YTHomeDetailModel *)model
{
    _model = model;
    
    [self.likeButton setTitle:model.likes forState:UIControlStateNormal];
    [self.likeButton setTitle:model.likes forState:UIControlStateSelected];

    self.likeButton.selected = [model.isLike boolValue];
    NSLog(@"%d",self.likeButton.selected);

}
- (IBAction)likeButtonClick:(UIButton *)sender
{
    
    if (!YTNetworkManager.shareManager.account.auth) {
        [NSNotificationCenter.defaultCenter postNotificationName:kShouldLoginNotication object:nil];
        return;
    }

    
    [YTNetworkManager.shareManager requestLikesArticleWithTid:self.model.tid
                                                         tuid:self.model.uid
                                                   completion:^(BOOL isSucc, NSString *StatusInfo)
    {
        if (!isSucc) {
            [self.superview showTipWithTipStr:StatusInfo];
            return ;
        }
        
        self.likeButton.selected = YES;
        StatusInfo ? [self showAwardWithTipStr:[NSString stringWithFormat:@"点赞成功 +%@算力",StatusInfo]] : [self showTipWithTipStr:@"点赞成功"];
        [self.likeButton setTitle:[NSString stringWithFormat:@"%d",(self.model.likes.intValue+1)] forState:UIControlStateSelected];
    }];
}
@end
